<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
 	<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
 	<script type="text/javascript" src="<%=contextPath %>/static/bootstrap-fileinput/js/fileinput.js"></script>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <div class="ibox-title" style="border-color: white;">
                    <div class="row">
                        <div class="col-sm-12">
							<div class="form-group form-inline">
								<span> 姓名：</span>
								<input id="name" type="text" placeholder="请输入姓名" class="input-sm form-control">
								<span>公司名称: </span>
                                <input id="companyName" type="text" placeholder="请输入公司名称" class="input-sm form-control">
								<span> 岗位名称：</span>
								<input id="position" type="text" placeholder="请输入岗位名称" class="input-sm form-control">
								<span> 所在城市：</span>
								<input id="city" type="text" placeholder="请输入所在城市" class="input-sm form-control">
							</div>
						</div>
						<div class="col-sm-12">
							<div class="form-group form-inline">
							<span> 手机号码：</span>
								<input id="phone" type="text" placeholder="请输入手机号码" class="input-sm form-control" onblur="isPhone('phone',this.value)">
							<span> 创建人：</span>
							<select id="createUserId" class="form-control">
								<option value="">==请选择==</option>
								<c:forEach var="user"  items="${users }">
								<option value="${user.id }">${user.dep.depName} -/- ${user.truename }</option>
								</c:forEach>
							</select>
							<span>起止时间：</span>
							<input id="startDate" type="text" placeholder="请输入开始时间" class="input-sm form-control form_datetime" readonly="readonly">—
							<input id="endDate" type="text" placeholder="请输入结束时间" class="input-sm form-control form_datetime" readonly="readonly">
							</div>
						</div>
						<div class="col-sm-12">
						    <div class="form-group form-inline">
							<a id="find_btn" type="button" class="btn btn-sm btn-primary">搜索</a>
                               <a id="reset_btn" type="button" style="margin-left: 20px;" class="btn btn-sm btn-info"> 重置</a>
                            <s:hasPermission name="workSearch:add">
                            <a class="btn btn-sm btn-success" style="margin-left: 20px;" onclick="showadd();">添加</a>
                            </s:hasPermission>
                            <s:hasPermission name="workSearch:add">
                            <a id="deleteAll" class="btn btn-sm btn-danger" style="margin-left: 20px;" onclick="showalldel();">批量删除</a>
                            </s:hasPermission>
                            <s:hasPermission name="workSearch:input">	
                            <input type="file" id="file" name="file" class="input-sm form-control" style="display: none;" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" onchange="showinput();">                            
                            <a id="excel" class="btn btn-sm btn-warning" style="margin-left: 20px;" onclick="$('input[id=file]').click();" title="导入Excel">导入Excel</a>
                            </s:hasPermission>
							</div>
						</div>
                    </div>
                </div>
                <!-- biaogebigin -->
                <div class="ibox-content" style=" padding-left: 0px; margin-top: 10px;">
                    <div class="jqGrid_wrapper">
                        <table id="table_list"></table>
                        <div id="pager_list"></div>
                    </div>
                </div>
                <!-- tableover -->
            </div>
            <!-- PAGE CONTENT ENDS HERE -->

        </div>
        <!--/row-->
    </div>
    <!--/#page-content-->
</div>
<!--/.fluid-container#main-container-->
<script type="text/javascript">
$(".form_datetime").datetimepicker({
	  minView: "month",//设置只显示到月份
	  format : "yyyy-mm-dd",//日期格式
	  autoclose:true,//选中关闭
	  todayBtn: true,//今日按钮
    language:  'zh-CN',
});
    $(top.hangge());
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#table_list").jqGrid({
            url: '<%=contextPath%>/workSearch/listData',
            datatype: "json",
            postData: {}, //发送数据
            autowidth: true,
            rownumbers: true,
            shrinkToFit: true,
            sortname: 'createDate',
            sortorder: "desc",
            mtype: "post",
            rowNum: 10,
            rowList: [10, 20, 30],
            colNames: [
			"id",
			"沟通事项",
			"公司名称",
			"区域",
			"所在城市",
			"目标职位",
			"姓名",
			"性别",
			"年龄",
			"联系方式",
			"邮箱",
			"沟通记录",
			"备注",
			"创建人",
			"创建时间",
	         "操作"],
            colModel: [
			{name: "id",index: "id",hidden: true}, 
			{name:"isChange",index:"isChange",width:75},
			{name:"companyName",index:"companyName",width:75},
			{name:"area",index:"area",width:100},
			{name:"city",index:"city",width:75},
			{name:"postition",index:"postition",width:75},
			{name:"trueName",index:"trueName",width:60},
			{name:"sex",index:"sex",width:45},
			{name:"age",index:"age",width:45},
			{name:"contact",index:"contact",width:100},
			{name:"email",index:"email",width:100},
			{name:"records",index:"records",width:100,
				formatter: function (value, options, row) {
					var msg = "查看详情";
					if(value!=null){
						msg = value;
					}
                	return '<a onclick="openrecord(&quot;'+ row.id +'&quot;);" title="查看更多">'+msg+'</a>';
                }
			},
			{name:"remark",index:"remark",width:100},
			{name:"createUser.truename",index:"createUser.truename",width:60},
			{name:"createDate",index:"createDate",width:100,editable:false,formatter:"date",formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'}},
	        {
                formatter: function (cellvalue, options, row) {
                    return " <s:hasPermission name="workSearch:detail"><a class='btn btn-sm btn-info' title='查看' onclick='showeye(&quot;" + row.id + "&quot;)'><i class='icon-eye-open'></i></a></s:hasPermission> " 
                         + " <s:hasPermission name="workSearch:edit"><a class='btn btn-sm btn-primary' title='修改' onclick='showedit(&quot;" + row.id + "&quot;)'><i class='icon-edit'></i></a></s:hasPermission> "
                         + " <s:hasPermission name="workSearch:edit"><a class='btn btn-sm btn-warning' title='纳入人才库' onclick='showtalents(&quot;" + row.id + "&quot;)'><i class='icon-upload'></i></a></s:hasPermission> "
                         + " <s:hasPermission name="workSearch:edit"><a class='btn btn-sm btn-success' title='添加沟通记录' onclick='addrecord(&quot;" + row.id + "&quot;)'><i class='icon-comments'></i></a></s:hasPermission> "
                         + " <s:hasPermission name="workSearch:delete"><a class='btn btn-sm btn-danger' title='删除' onclick='del(&quot;" + row.id + "&quot;)'><i class='icon-trash'></i></a></s:hasPermission> ";
                },
                width: 250
            }],
            height: $(window).height() - 170,
            pager: "#pager_list",
            multiselect: true,//多选按钮
            //multiboxonly: true,
            viewrecords: true,
            hidegrid: false
        });
        //表格自适应高宽
        $(window).bind("resize", function () {
            var b = $(".jqGrid_wrapper").width();
            $("#table_list").setGridWidth(b);
            $("#table_list").setGridHeight($(window).height() - 170);
        })
        $("#table_list").navGrid('#pager_list', {edit: false, add: false, del: false, search: false})
        /* 判断是否有添加权限 */
        //检索
        $("#find_btn").click(function () {
        	//姓名
            var name = $("#name").val();
            //姓名
            var city = $("#city").val();
            //公司名称
            var company_name = $("#companyName").val();
            //岗位名称
            var position = $("#position").val();
            //手机号码
            var phone = $('#phone').val();
            //创建人
            var createUserId = $('#createUserId').val();
            //开始时间
            var startDate = $('#startDate').val();
            if(startDate!=""){
          	  startDate=startDate+" 00:00:00"
            }
            //结束时间
              var endDate = $('#endDate').val();
              if(endDate!=""){
              	endDate=endDate+" 23:59:59";
              }
            $("#table_list").jqGrid('setGridParam', {
                postData: {
                	'name': name,
                	'companyName':company_name,
                	'position':position,
                	'phone':phone,
                	'expectedCity':city,
                	'createuserid':createUserId,
                	'startDate':startDate,
                	'endDate':endDate
                	}, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });
        $("#reset_btn").click(function () {
        	$("#name").val('');
        	$("#companyName").val('');
        	$("#city").val('');
        	$('#phone').val('');
        	$('#createUserId').val('');
        	$('#startDate').val('');
        	$('#endDate').val('');
        	$("#position").val('');
        });
        
    function showalldel() {
    	// 全局变量，rowIds
		var rowIds = $("#table_list").jqGrid("getGridParam", "selarrrow");
		if(rowIds.length < 1) {
			swal({
				title : "请选择列表记录",
				type : "info",
				showCancelButton : false,
				confirmButtonText : "确定",
				animation : "slide-from-bottom",
				text: "2秒后自动关闭。", 
	    		timer: 2000, 
				closeOnConfirm : true
			});
		}else {
			$.ajax({
	            url: "<%=contextPath%>/workSearch/deleteList?ids="+rowIds,
	            type: "post",
	            dataType: "json",
	            cache: false,//上传文件无需缓存
	            processData: false,//用于对data参数进行序列化处理 这里必须false
	            contentType: false, //必须
	            beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#deleteAll").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
	            success: function (data) {
	            	if(data.code ==200){
	            		swal({
	            			title: "您确定要批量删除吗",
	            		    text: "删除后将无法恢复，请谨慎操作！",
	            		    type: "warning",
	            		    showCancelButton: true,
	            		    confirmButtonColor: "#DD6B55",
	            		    confirmButtonText: "删除",
	            		    animation:"slide-from-bottom",
	            		    cancelButtonText:"取消",
	            		    closeOnConfirm: true
						}, function() {
							$("#table_list").trigger("reloadGrid");
							top.Dialog.close();
						});
	            	}
	            },    
				complete: function () {
			        $("#deleteAll").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
	        }) 
		}
	}
    //查看
    function showeye(id) {
        openyem("查看工作记录表", "<%=contextPath%>/workSearch/detailView?id=" + id, 550, 500);
    }
    //删除
    function del(id) {
        swalopen(id, "<%=contextPath%>/workSearch/delete");
    };
    //修改
    function showedit(id) {
        openyem("修改工作记录表", "<%=contextPath%>/workSearch/editView?id=" + id, 550, 500);
    }
    //添加
    function showadd(id) {
        openyem("添加工作记录表", "<%=contextPath%>/workSearch/addView", 550, 500);
    }
    function showinput() {
    	var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
        if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
            return;
        }
    	if(fileObj!=""){
    		var formFile = new FormData();
            formFile.append("action", "UploadVMKImagePath");  
            formFile.append("file", fileObj); //加入文件对象
            var data = formFile;
            $.ajax({
                url: "<%=contextPath%>/workSearch/inputExl",
                data: data,
                type: "post",
                dataType: "json",
                cache: false,//上传文件无需缓存
                processData: false,//用于对data参数进行序列化处理 这里必须false
                contentType: false, //必须
                beforeSend: function () {
    		        // 禁用按钮防止重复提交
    				$("#excel").attr("disabled","disabled");
    				swal("信息已经提交，请等待后台处理~！");
    		    },
                success: function (data) {
                	if(data.code ==200){
                		swal({
    						title : data.message,
    						type : "success",
    						showCancelButton : false,
    						confirmButtonText : "确定",
    						animation : "slide-from-bottom",
    						text: "2秒后自动关闭。", 
          	    			timer: 2000, 
    						closeOnConfirm : true
    					}, function() {
    						$("#table_list").trigger("reloadGrid");
    						top.Dialog.close();
    					});
                	}
                },    
    			complete: function () {
    		        $("#excel").removeAttr("disabled");
    		    },
    		    error: function (data) {
    		    	swal("错误", data.message, "error");
    		    }
            }) 
    	}
    }
    function showtalents(id) {
    	openyem("纳入人才库", "<%=contextPath%>/workSearch/addResume?id="+id, 1080, 850);
	}
    function addrecord(id){
    	openyem("添加沟通记录", "<%=contextPath%>/recommendResult/addView?recommandId="+id+"&type=1", 500, 400);
    }
    function openrecord(id) {
    	openyem("查看沟通记录", "<%=contextPath%>/demandCommunicate/list?workId=" + id, 1080, 550);
	}
</script>
</body>
</html>

